#include<bits/stdc++.h>
using namespace std;
int T,n,a[100005],ans,color[100005];
void dfs(int now){
    if(now==n+1){
        int x=0;
        for(int i=1;i<=n;i++){
            for(int j=i-1;j>=1;j--){
                if(color[j]==color[i]){
                    if(a[j]==a[i]){
                        x+=a[i];
                    }else{
                        break;
                    }
                }
            }
        }
        ans=max(ans,x);
        return;
    }
    color[now]=1;
    dfs(now+1);
    color[now]=2;
    dfs(now+1);
}
int main(){
    freopen("color.in","r",stdin);
    freopen("color.out","w",stdout);
    scanf("%d",&T);
    while(T--){
        scanf("%d",&n);
        ans=0;
        for(int i=1;i<=n;i++){
            scanf("%d",&a[i]);
        }
        dfs(1);
        printf("%d\n",ans);
    }
    return 0;
}

